package com.spic.business.plan.drill.controller;

import com.spic.business.common.core.utils.poi.BusinessExcelUtil;
import com.spic.business.plan.drill.domain.PlanDrillPlan;
import com.spic.business.plan.drill.service.IPlanDrillPlanService;
import com.spic.common.core.utils.poi.ExcelUtil;
import com.spic.common.core.web.controller.BaseController;
import com.spic.common.core.web.domain.AjaxResult;
import com.spic.common.core.web.page.TableDataInfo;
import com.spic.common.log.annotation.Log;
import com.spic.common.log.enums.BusinessType;
import com.spic.common.security.annotation.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * 应急预案演练计划Controller
 *
 * @author spic
 * @date 2021-10-15
 */
@RestController
@RequestMapping("plan/drill")
public class PlanDrillPlanController extends BaseController
{
    @Autowired
    private IPlanDrillPlanService planDrillPlanService;

    /**
     * 查询应急预案演练计划列表
     */
    @PreAuthorize(hasPermi = "business/plan:drill:list")
    @GetMapping("/list")
    public TableDataInfo list(PlanDrillPlan planDrillPlan)
    {
        startPage();
        List<PlanDrillPlan> list = planDrillPlanService.selectPlanDrillPlanList(planDrillPlan);
        return getDataTable(list);
    }

    /**
     * 导出应急预案演练计划列表
     */
    @PreAuthorize(hasPermi = "business/plan:drill:export")
    @Log(title = "应急预案演练计划", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PlanDrillPlan planDrillPlan) throws IOException
    {
        List<PlanDrillPlan> list = planDrillPlanService.selectPlanDrillPlanList(planDrillPlan);
        ExcelUtil<PlanDrillPlan> util = new BusinessExcelUtil<PlanDrillPlan>(PlanDrillPlan.class);
        util.exportExcel(response, list, "应急预案演练计划数据");
    }

    /**
     * 获取应急预案演练计划详细信息
     */
    @PreAuthorize(hasPermi = "business/plan:drill:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(planDrillPlanService.selectPlanDrillPlanById(id));
    }

    /**
     * 新增应急预案演练计划
     */
    @PreAuthorize(hasPermi = "business/plan:drill:add")
    @Log(title = "应急预案演练计划", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PlanDrillPlan planDrillPlan)
    {
        return toAjax(planDrillPlanService.insertPlanDrillPlan(planDrillPlan));
    }

    /**
     * 修改应急预案演练计划
     */
    @PreAuthorize(hasPermi = "business/plan:drill:edit")
    @Log(title = "应急预案演练计划", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PlanDrillPlan planDrillPlan)
    {
        return toAjax(planDrillPlanService.updatePlanDrillPlan(planDrillPlan));
    }

    /**
     * 删除应急预案演练计划
     */
    @PreAuthorize(hasPermi = "business/plan:drill:remove")
    @Log(title = "应急预案演练计划", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(planDrillPlanService.deletePlanDrillPlanByIds(ids));
    }


    /**
     * 获取应急预案演练计划详细信息
     */
    @GetMapping(value = "/detail/{id}")
    public AjaxResult getDetailInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(planDrillPlanService.selectPlanDrillPlanDetailById(id));
    }
}
